﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.ManageOrder
{
    public partial class OrderShow : System.Web.UI.Page
    {
        public DealInfo deal = new DealInfo();
        public IList<OrderDetail> ordlist = new List<OrderDetail>();
        public OrderDetailBLL ordbll = new OrderDetailBLL();
        public DealInfoBLL debll = new DealInfoBLL();
        public int state = 9;
        public int page=1;
        int pageSize = 15;
        public int id = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            id = Convert.ToInt32(Request["id"]);
            if (!string.IsNullOrEmpty(Request["page"]))
            {
                page = Convert.ToInt32(Request["page"]);
            }
            if (!IsPostBack)
            {
                Bind();
            }

        }
        public void Bind()
        {
            deal = debll.GetDealInfoById(id);
            this.labUserName.Text  = deal.UserName;
            this.labOrderId.Text = deal.OrderId;
            this.labendTime.Text = deal.EndDate.ToShortDateString();
            this.labaDtime.Text = deal.AddDate.ToShortDateString();
            this.labtot.Text = deal.TotalPrice.ToString();
            
            state = deal.State;
            ordlist = ordbll.GetDealInfoId(id, page, pageSize);
        }
        public string GetPager()
        {
            int total = ordbll.GetDealInfoId(id);
            return EnPager.GetPager(total, pageSize, page, "&id=" + id);
        }

        protected void btnReply_Click(object sender, EventArgs e)
        {
            int iid = Convert.ToInt32(Request["iid"]);
            DealInfo des = new DealInfo();
            DealInfo deals = new DealInfo();
            des = debll.GetDealInfoById(iid);
            deals.Id = iid;
            if (des.Type == 0)
            {
                deals.Type = des.Type;
                deals.TypeCon = des.TypeCon;
            }
            else
            {
                deals.Type = des.Type;
                if (Request["Con"].ToString() == "" || Request["Con"] == null)
                {
                    StringUtil.Alert("地址不能为空！", "-1");
                }
                else
                {
                    deals.TypeCon = Util.StringUtil.checkStr(Request["Con"]);
                }
            }
          
            deals.TotalPrice =Convert .ToDecimal ( this.labtot.Text);
            deals.OrderId = this.labOrderId.Text;
            deals.State = Convert.ToInt32(Request["select1"]);
            deals.UserName = this.labUserName.Text;
            deals.EndDate = des.EndDate;
            deals.AddDate = des.AddDate;
           

            debll.entity = deals;
            bool b = debll.UpDate();
            if (b)
            {
                StringUtil.Alert("修改成功！", "OrderShow.aspx?id="+id);
            }
            else
            {
                StringUtil.Alert("修改失败！", "-1");
            }
        }


        public string Sub(bool b, int n, string m)
        {
            string ss;
            int con = m.Length;
            if (n < con)
            {
                ss = m.Substring(0, n);
                if (b)
                {
                    ss = ss + "...";
                }
            }
            else
            {
                ss = m;
            }
            return ss;
        }
    }
}
